﻿<template>
  <div>
    <!--查询参数-->
    <params
      ref="params"
      @handleRefresh="handleRefresh"
      :loading="loading"
    ></params>
    <!--表格页面-->
    <my-table
      ref="myTable"
      title="用户消费记录"
      :columns="columns"
      :loading="loading"
      :dataSource="dataSource"
      @loadData="loadData"
      @handleExport="handleExport"
      @handleDetail="handleDetail"
      exportAction="consumptionHistory_export"
      detailAction="consumptionHistory_details"
    />
    <detail
      v-if="modifyEntity.showDetail"
      @handleRefresh="handleRefresh"
      :modifyEntity="modifyEntity"
    />
  </div>
</template>
<script>
import detail from "./detail";
import myTable from "_c/myTable/index";
import params from "./components/params";
import {
  consumptionhistoryColumns,
  queryConsumptionhistoryPage,
} from "./consumptionhistory";

export default {
  name: "Consumptionhistory",
  components: { params, detail, myTable },
  data() {
    return {
      modifyEntity: {
        // 传递的主键
        id: "",
        // 页面操作类型
        operation: "",
        // 是否展示编辑页面
        showModify: false,
        // 是否展示详情页面
        showDetail: false,
      },
      // 加载动画
      loading: false,
      // 绑定的数据源
      dataSource: [],
      // 表格绑定的列
      columns: consumptionhistoryColumns,
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    //#region 查询列表
    // 保存/修改后刷新表格
    handleRefresh() {
      this.modifyEntity.showDetail = false;
      this.modifyEntity.showModify = false;
      this.$refs.myTable.pagination.current = 1;
      this.loadData();
    },
    // 加载数据
    loadData() {
      this.loading = true;
      let that = this;
      let queryParams = {
        ...this.$refs.params.params,
        current: this.$refs.myTable.pagination.current,
        pageSize: this.$refs.myTable.pagination.pageSize,
      };
      queryConsumptionhistoryPage(queryParams)
        .then((res) => {
          let { data, totalCount } = res.data;
          that.dataSource = data;
          this.$refs.myTable.pagination.total = totalCount;
          that.loading = false;
        })
        .catch(() => {
          that.loading = false;
        });
    },
    //#endregion

    //#region 详情
    // 打开详情页面
    handleDetail(item) {
      this.modifyEntity = {
        id: item.id,
        showDetail: true,
        showModify: false,
        operation: this.operationFlag.Detail,
      };
    },
    //#endregion

    //#region 导入
    // 导入数据
    handleImport() {},
    //#endregion

    //#region 导出
    // 导出数据
    handleExport() {},
    //#endregion
  },
};
</script>
